#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int d[maxn],a[maxn],v[maxn],n,m,t,L,V,P[maxn];
int check1=1,usefl[maxn],ans1,ans2;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    while(t--)
    {
        int pk;
        ans1=ans2=0;
        memset(usefl,0,sizeof(usefl));
        //cin>>n>>m>>L>>V;
        cin>>n>>m>>L>>V;
        //m=x;
        for(int i=1;i<=n;i++)
            {scanf("%d %d %d",d+i,v+i,a+i);if(a[i]!=0) check1=0;}
        for(int i=1;i<=m;i++)
            scanf("%d",P+i);
        sort(P+1,P+m+1);
        for(int i=1;i<=n;i++)
            {
                int p=lower_bound(P+1,P+m+1,d[i])-P;
                if(p>m) continue;
                if(v[i]>V) ans1++;
            }
        if(check1)
        {

            //(int i=1;i<=n;i++)
                //if(usefl[i]) ans2++;
                if(ans1==0) printf("%d %d",0,m);
                else
            printf("%d %d\n",ans1,m-1);

        }

    }
    return 0;
}
